package com.cskaoyan.service.impl;

import com.cskaoyan.bean.CskaoyanmallCategory;
import com.cskaoyan.bean.CskaoyanmallCategoryExample;
import com.cskaoyan.bean.vo.WXCatalogCurrentVO;
import com.cskaoyan.bean.vo.WXCatalogVO;
import com.cskaoyan.mapper.CskaoyanmallCategoryMapper;
import com.cskaoyan.service.WXCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WXCatalogServiceImpl implements WXCatalogService {

    @Autowired
    CskaoyanmallCategoryMapper categoryMapper;


    @Override
    public WXCatalogVO index() {
        WXCatalogVO wxCatalogVO = new WXCatalogVO( );

        CskaoyanmallCategoryExample categoryExample = new CskaoyanmallCategoryExample( );
        CskaoyanmallCategoryExample.Criteria criteria = categoryExample.createCriteria( );
        criteria.andLevelEqualTo("L1");
        List<CskaoyanmallCategory> categoryList = categoryMapper.selectByExample(categoryExample);
        wxCatalogVO.setCategoryList(categoryList);

        wxCatalogVO.setCurrentCategory(categoryList.get(0));

        CskaoyanmallCategoryExample categoryExample1 = new CskaoyanmallCategoryExample( );
        CskaoyanmallCategoryExample.Criteria criteria1 = categoryExample1.createCriteria( );
        criteria1.andPidEqualTo(categoryList.get(0).getId( ));
        List<CskaoyanmallCategory> categoryList1 = categoryMapper.selectByExample(categoryExample1);
        wxCatalogVO.setCurrentSubCategory(categoryList1);

        return wxCatalogVO;
    }

    @Override
    public WXCatalogCurrentVO current(Integer id) {
        WXCatalogCurrentVO wxCatalogCurrentVO = new WXCatalogCurrentVO( );

        CskaoyanmallCategoryExample categoryExample = new CskaoyanmallCategoryExample( );
        CskaoyanmallCategoryExample.Criteria criteria = categoryExample.createCriteria( );
        criteria.andIdEqualTo(id);
        List<CskaoyanmallCategory> categoryList = categoryMapper.selectByExample(categoryExample);
        CskaoyanmallCategory category = categoryList.get(0);
        wxCatalogCurrentVO.setCurrentCategory(category);

        CskaoyanmallCategoryExample categoryExample1 = new CskaoyanmallCategoryExample( );
        CskaoyanmallCategoryExample.Criteria criteria1 = categoryExample1.createCriteria( );
        criteria1.andPidEqualTo(category.getId( ));
        List<CskaoyanmallCategory> categoryList1 = categoryMapper.selectByExample(categoryExample1);
        wxCatalogCurrentVO.setCurrentSubCategory(categoryList1);

        return wxCatalogCurrentVO;
    }
}
